<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a {
            width: 50px;
            height: 50px;
            background-color: #f00;
            position: absolute;
            left: 1000px;
        }
    </style>
</head>

<body>

    <div class="a"></div>


    <script>


        // 缓冲运动  --- 减速运动

        //   缓冲因子n  把路程等分 n份  

        //     缓冲因子越大，初始速度越小
        //     缓冲因子越小，初始速度越大


        var oDiv = document.querySelector('.a');

        move(oDiv, 0, 'left');


        function move(ele, end, prop, cb) {
            // 获取开始的位置
            var cur = parseInt(getComputedStyle(ele)[prop]);

            t = setInterval(function () {
                // 把剩余的路程等分10   分不完...
                speed = (end - cur) / 10;
                // 0.2   1   向上取整
                // -0.2  -1  向下取整
                speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);

                cur += speed;
                ele.style[prop] = cur + 'px';
                if (Math.abs(end - cur) <= Math.abs(speed)) {
                    clearInterval(t);
                    ele.style[prop] = end + 'px';
                    cb && cb()
                }
            }, 20)
        }




    </script>

</body>

</html>